package com.wangjiyuan.shiwupai.mine.activitiy;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.Log;
import com.wangjiyuan.shiwupai.R;
import com.wangjiyuan.shiwupai.base.BaseActivity;

public class SettingActivity extends BaseActivity implements View.OnClickListener {

    private Toolbar toolBar_setting_back;
    private LinearLayout ll_setting_clean, ll_setting_advise,
            ll_setting_grade, ll_setting_shareApp;
    private UMShareListener umShareListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        initToolBar();
        initView();
    }

    private void initView() {
        ll_setting_clean = (LinearLayout) findViewById(R.id.ll_setting_clean);
        ll_setting_advise = (LinearLayout) findViewById(R.id.ll_setting_advise);
        ll_setting_grade = (LinearLayout) findViewById(R.id.ll_setting_grade);
        ll_setting_shareApp = (LinearLayout) findViewById(R.id.ll_setting_shareApp);

        ll_setting_clean.setOnClickListener(this);
        ll_setting_advise.setOnClickListener(this);
        ll_setting_grade.setOnClickListener(this);
        ll_setting_shareApp.setOnClickListener(this);
    }

    private void initToolBar() {
        toolBar_setting_back = (Toolbar) findViewById(R.id.toolBar_setting_back);
        toolBar_setting_back.setTitle("设置");
        toolBar_setting_back.setNavigationIcon(R.mipmap.icon_back_black);
        toolBar_setting_back.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_setting_clean:
                Toast.makeText(mContent, "清除缓存", Toast.LENGTH_SHORT).show();
                break;
            case R.id.ll_setting_advise:
                Toast.makeText(mContent, "提建议", Toast.LENGTH_SHORT).show();
                break;
            case R.id.ll_setting_grade:
                Toast.makeText(mContent, "评分", Toast.LENGTH_SHORT).show();
                break;
            case R.id.ll_setting_shareApp:
                new ShareAction(SettingActivity.this).setPlatform(SHARE_MEDIA.QQ)
                        .withText("hello")
                        .setCallback(umShareListener)
                        .share();

                    umShareListener = new UMShareListener() {
                    @Override
                    public void onResult(SHARE_MEDIA platform) {
                        Log.d("plat", "platform" + platform);

                        Toast.makeText(SettingActivity.this, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();

                    }

                    @Override
                    public void onError(SHARE_MEDIA platform, Throwable t) {
                        Toast.makeText(SettingActivity.this, platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
                        if (t != null) {
                            Log.d("throw", "throw:" + t.getMessage());
                        }
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA platform) {
                        Toast.makeText(SettingActivity.this, platform + " 分享取消了", Toast.LENGTH_SHORT).show();
                    }
                };
                break;
        }
    }
}
